/**
 * @Description:
 * @Author bianpengfei
 * @create 2021/5/11 18:16
 */
import client from 'webpack-theme-color-replacer/client'
import forElementUI from 'webpack-theme-color-replacer/forElementUI'

export const changeElementPrimaryColor = (color, callback) => {
  const options = {
    newColors: [...forElementUI.getElementUISeries(color)], // new colors array, one-to-one corresponde with `matchColors`
    appendToEl: 'body', // optional. The element selector for appending child with `<style>`, default is 'body'. Using `appendToEl: 'body'` can make the css priority higher than any css in <head>
    changeUrl(cssUrl) {
      // eslint-disable-next-line no-undef
      return `${PUBLIC_URL}${cssUrl}` // while router is not `hash` mode, it needs absolute path
    }
  }
  client.changer.changeColor(options, Promise).then(callback)
}
